package com.example.controll.comment;


import com.example.config.R;
import com.example.domain.comment;
import com.example.service.comment.commentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/comment")
public class commentControll {
    @Resource
    private commentService commentService;


    @RequestMapping("/linglun")
    private R update(comment comment){
        String openid="'"+comment.getCommentuserid()+"'";
        commentService.update(comment.getArticlesid(),openid);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(simpleDateFormat.format(date));
        String format = simpleDateFormat.format(date);
        comment.setTime(format);

        boolean insert = commentService.insert(comment);

        return new R(insert,insert?"评论成功":"评论失败");
    }

    @RequestMapping("/select")
    private R select(int articlesid){
        return new R(true,commentService.select1(articlesid));
    }


    @RequestMapping("/selectall")
    private R selectall(int a,int b,String name){
        name="'%"+name+"%'";
        return new R(true,commentService.selectall(a,b,name));
    }

    @RequestMapping("/num")
    private R num(){
        return new R(true,commentService.num());
    }


}
